import { pa } from 'element-plus/es/locale';
<template>
  <el-dialog v-model="showDialog" title="发送提醒信息">
    <!-- 设计标题和内容 -->
    <el-form ref="dialogFormRef" :model="messageForm" :rules="dataRules" label-width="auto">
      <el-form-item label="标题" prop="title">
        <el-input v-model="messageForm.title" placeholder="请输入标题" />
      </el-form-item>
      <el-form-item label="主要内容" prop="mainText">
        <el-input v-model="messageForm.mainText" type="textarea" placeholder="请输入内容" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="showDialog = false">取 消</el-button>
        <el-button type="primary" @click="sendMessage">确 定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { sendMessageApi } from '/@/api/patient/sendMessage';


const showDialog = ref(false)

const dialogFormRef = ref()

const messageForm = ref({
  title: '',
  mainText: '',
})

const dataRules = ref({
  title: [
    { required: true, message: '请输入标题', trigger: 'blur' },
    { max: 100, message: '长度在 100 个字符以内', trigger: 'blur' }
  ],
  mainText: [
    { max: 400, message: '长度在 400 个字符以内', trigger: 'blur' }
  ]
})

const sendMessage = () => {
  dialogFormRef.value.validate((valid: boolean) => {
    if (valid)
    {
      // TODO: 发送信息
      sendData.value.message = messageForm.value
      console.log('发送信息', sendData.value);
      sendMessageApi(sendData.value)
      showDialog.value = false
    }
  })
}

const sendData = ref({
  doctorUid: <string | number>'',
  patientUid: <string | number>'',
  message: <string | object | null>null,
})

const openDialog = (idObject: { doctorUid: string | number, patientUid: string | number }) => {
  // 设置患者id和医生id
  sendData.value.doctorUid = idObject.doctorUid
  sendData.value.patientUid = idObject.patientUid
  showDialog.value = true
}

// 暴露变量
defineExpose({
  openDialog,
});

</script>
